package com.zooltech.samples.ws;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.xml.ws.Endpoint;

/**
 * 通过servlet来发布webservice的样例
 */
@WebServlet(urlPatterns={"/HelloServlet"},asyncSupported=true)
public class HelloServlet extends GenericServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloServlet() {
        super();
    }
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		System.out.println("启动Webservice......");
		Endpoint.publish("http://localhost:8088/ws/HelloService", new HelloWS());
		System.out.println("Webservice结束。");
	}
	@Override
	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		//response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		Writer wr = response.getWriter();
		wr.write("<a href='http://localhost:8088/ws/HelloService?WSDL'>点击</a>");
		wr.close();
	}
}
